package org.example;

public class FizzBuzz {
    private int number;
    private String tmp;
    public FizzBuzz(int number) {
        if (number < 1 || number > 100) {
            throw new IllegalArgumentException("无效输入");
        }
        this.number = number;
    }
    public String fizzBuzz(){
        tmp = "";
//        if (number % 3 == 0 && number % 5 == 0)
//            return "FizzBuzz";
//        else if (number % 5 == 0)
//            return "Buzz";
//        else if (number % 3 == 0)
//            return "Fizz";
        //尝试优化结果
        if (number % 3 == 0 || String.valueOf(number).contains(String.valueOf(3)))
            tmp += "Fizz";
        if (number % 5 == 0 || String.valueOf(number).contains(String.valueOf(5)))
            tmp += "Buzz";
        if (tmp.length() != 0)
            return tmp;

        return String.valueOf(number);
    }
}
